var dialog = new auiDialog({});

function openDialog(type, num, pwd, price) {
    switch (type) {
        case "callback":
            dialog.alert({
                    title: "选择发卡方式",
                    buttons: ["短信发送卡密"],
                    span: " "
                },
                function(ret) {
                    if (ret.buttonIndex == 1) {
                        dialog.prompt({
                            title: "输入发送手机号",
                            text: "请输入手机号",
                            buttons: ["发送卡密"],
                            span: ""
                        });
                        $(".aui-dialog-btn").click(function() {
                            var phone = $(".aui-dialog-body input").val();
                            if (phone == "") {
                                // showError("fail");
                            } else if (checkMobile()) {
                                //失去焦点验证手机号
                                var data = {
                                    ecardSn: num,
                                    mobile: phone,
                                    password: pwd
                                };
                                $.ajax({
                                    type: "post",
                                    url: url + "station/messagecard",
                                    data: data,
                                    success: function(result) {
                                        if (result.code == 200) {
                                            showDefaultMsg("success");
                                        } else {
                                            showDefaultMsg("fail");
                                        }
                                    }
                                });
                            }
                        });
                    } else if (ret.buttonIndex == 2) {
                        dialog.alert({
                            title: "卡号：" + num,
                            msg: '<div id="code" ></div>',
                            buttons: " ",
                            span: '<div style="padding-bottom:18px;">请使用艾美一族商城扫一扫，领取E卡</div>'
                        });

                        $(".aui-dialog-footer").css("display", "none");
                        var code = "eno:" + num + ";epw:" + pwd + ";mon:" + price;

                        $("#code").qrcode({
                            render: "canvas", //table方式
                            width: 230, //宽度
                            height: 230, //高度
                            text: code
                        });
                    }
                }
            );
            break;
    }
}

apiready = function() {
    api.parseTapmode();
};
var toast = new auiToast({});

//提示发送成功和失败
function showDefaultMsg(type) {
    console.log(123);
    switch (type) {
        case "success":
            toast.success({
                title: "短信发送成功",
                duration: 1500
            });
            break;
        case "fail":
            toast.fail({
                title: "短信发送失败",
                duration: 1500
            });
            break;
    }
}


//提示号码不能为能为空
function showError(type) {
    switch (type) {
        case "fail":
            toast.fail({
                title: "号码不能为空",
                duration: 1500
            });
            break;
    }
}
//提示号码格式不正确
function showFail(type) {
    switch (type) {
        case "fail":
            toast.fail({
                title: "号码格式不正确",
                duration: 1500
            });
            break;
    }
}
//验证手机号码
function checkMobile() {
    var sMobile = $(".aui-dialog-body input").val();
    if (!/^1(3|4|5|7|8)\d{9}$/.test(sMobile)) {
        showFail("fail");
        return false;
    } else {
        return true;
    }
}